package com.teamide.http;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class FileResource implements Resource {

	public FileResource() {

	}

	public FileResource(String name) {

		this.name = name;
	}

	public FileResource(String name, byte[] bytes) {

		this.name = name;
		this.bytes = bytes;
	}

	public FileResource(String name, File file) {

		this.name = name;
		this.file = file;
	}

	public FileResource(File file) {

		this.name = file.getName();
		this.file = file;
	}

	private String name;

	private File file;

	private byte[] bytes;

	public String getName() {

		return name;
	}

	public void setName(String name) {

		this.name = name;
	}

	public File getFile() {

		return file;
	}

	public void setFile(File file) {

		this.file = file;
	}

	public byte[] getBytes() {

		return bytes;
	}

	public void setBytes(byte[] bytes) {

		this.bytes = bytes;
	}

	public InputStream getStream() {

		if (bytes != null) {
			return new ByteArrayInputStream(bytes);
		}
		if (file != null) {
			try {
				return new FileInputStream(file);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return null;
	}

}
